import sys
import re

f = open(sys.argv[1], 'r')
precision = {}
recall = {}
p_total = {}
r_total = {}
for i in f:
  ff = open(i.strip(), 'r')
  fill_dict = precision
  fill_total = p_total
  for j in ff:
    if j.strip() == 'RECALL':
      fill_dict = recall
      fill_total = r_total
      continue

    m = re.match('^(.*): (.*)$', j);
    if m:
      if float(m.groups()[1]) < 1.0:
        continue
      if m.groups()[0] not in fill_dict:
        fill_dict[m.groups()[0]] = 0.0
      fill_dict[m.groups()[0]] += float(m.groups()[1])
      if m.groups()[0] not in fill_total:
        fill_total[m.groups()[0]] = 0
      fill_total[m.groups()[0]] += 1
  ff.close()
f.close()

print 'PRECISION'
for k in sorted(precision):
  print '%s: %f' % (k, precision[k]/float(p_total[k]))

print 'RECALL'
for k in sorted(recall):
  print '%s: %f' % (k, recall[k]/float(r_total[k]))
